
package com.chongchong.multifile.wrapper;

import com.chongchong.multifile.entity.FileList;
import com.chongchong.core.mp.support.BaseEntityWrapper;
import com.chongchong.core.tool.utils.BeanUtil;
import com.chongchong.core.tool.utils.SpringUtil;
import com.chongchong.multifile.service.IFileTypeService;
import com.chongchong.multifile.vo.FileListVO;
import com.chongchong.system.entity.FileType;
import com.chongchong.user.entity.User;
import com.chongchong.user.service.IUserService;

/**
 * 文件分块上传历史表包装类,返回视图层所需的字段
 *
 * @author en
 * @since 2022-07-18
 */
public class FileListWrapper extends BaseEntityWrapper<FileList, FileListVO>  {
	private static IUserService userService;

	private static IFileTypeService fileTypeService;

	static {
		userService = SpringUtil.getBean(IUserService.class);
		fileTypeService = SpringUtil.getBean(IFileTypeService.class);
	}
    public static FileListWrapper build() {
        return new FileListWrapper();
    }

	@Override
	public FileListVO entityVO(FileList fileList) {

		FileListVO fileListVO = BeanUtil.copy(fileList, FileListVO.class);
		User user = null;
		if(fileListVO !=null && fileListVO.getCreateUserId() !=null){
			user = userService.getById(fileListVO.getCreateUserId());
			if(user!=null){
				fileListVO.setCreateUserName(user.getName());
			}
		}

		if(fileListVO !=null && fileListVO.getUpdateUserId() !=null){
			user = userService.getById(fileListVO.getUpdateUserId());
			if(user!=null){
				fileListVO.setUpdateUserName(user.getName());
			}
		}

		if(fileListVO !=null && fileListVO.getFileTypeId() !=null){
			FileType ft = fileTypeService.getById(fileListVO.getFileTypeId());
			if(ft != null){
				fileListVO.setFileTypeName(ft.getTypeName());
			}

		}
		if(fileListVO!=null && fileListVO.getAuditUserId() != null){
           user = userService.getById(fileListVO.getAuditUserId());
		   if(user != null){
			   fileListVO.setAuditor(user.getName());
		   }
		}
		return fileListVO;
	}

}
